<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "admin".
 *
 * @property integer $id
 * @property string $adm_username
 * @property string $adm_password
 */
class Admin extends \yii\db\ActiveRecord 
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'admin';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            ['adm_username', 'required','message' => '用户名不能为空'],
            ['adm_password', 'required','message' => '用户密码不能为空'],
            ['adm_username','unique','on' => 'create','message' => '用户名已存在'],
            [['adm_username', 'adm_password'], 'string', 'max' => 255],
            ['role_id','required','on' => 'create'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'adm_username' => '用户名',
            'adm_password' => '用户密码',
            'role_id' => '用户角色',
        ];
    }
    
    public function getRolename($role_id)
    {
        $current_role = Role::findOne($role_id);
        
        
        
        return $current_role ? $current_role->role_name : '';
    }

}
